package com.supply.dl.widget.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.BindView;
import com.chad.library.adapter.base.BaseViewHolder;
import com.supply.dl.R;
import com.supply.dl.bean.WorkInfoBean;
import com.supply.dl.view.MyGridView;

import java.util.ArrayList;

public class WorkDetailsAdapter extends RecyclerView.Adapter<WorkDetailsAdapter.MyViewHolder>
{
	private Context mContext;
	private ImageAdapter imageAdapter;
	public ArrayList<WorkInfoBean> jobInfoList = new ArrayList<WorkInfoBean>(); //作业

	public WorkDetailsAdapter(Context context, ArrayList<WorkInfoBean> jobInfoList)
	{
		this.mContext = context;
		this.jobInfoList = jobInfoList;
	}

	@Override public WorkDetailsAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
	{
		return new WorkDetailsAdapter.MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.work_info_item, parent, false));
	}

	@Override public void onBindViewHolder(WorkDetailsAdapter.MyViewHolder holder, int position)
	{
		WorkInfoBean workInfoBean = jobInfoList.get(position);
		if (workInfoBean != null)
		{
			holder.txtCk.setText(workInfoBean.whName);
			holder.workKLbs.setText(workInfoBean.skuName);
			holder.txtGuiGe.setText(workInfoBean.unitId);
			holder.txtWeight.setText((workInfoBean.detailWeight+"").equals("null") ? "0" : (workInfoBean.detailWeight+""));
			holder.txtPcNum.setText(workInfoBean.batchNo);
			holder.txtPcNum.setEnabled(false);
			holder.txtPiece.setText((workInfoBean.amount+"").equals("null") ? "0" : (workInfoBean.amount+""));
			holder.txtPiece.setEnabled(false);
			holder.txtTon.setText((workInfoBean.weight+"").equals("null") ? "0" : (workInfoBean.weight+""));
			holder.txtTon.setEnabled(false);
			holder.txtStatus.setText(workInfoBean.stockStatus);
			holder.txtSquare.setText((workInfoBean.volume+"").equals("null") ? "0" : (workInfoBean.volume+""));
			holder.txtSquare.setEnabled(false);
			holder.txtWorkRecord.setText(workInfoBean.remark);
			holder.txtMangaer.setVisibility(View.GONE);
			holder.layoutBeizu.setVisibility(View.GONE);
			holder.txtSureWork.setVisibility(View.GONE);
			imageAdapter = new ImageAdapter(mContext, workInfoBean.jobAttachList);
			holder.myGridView.setAdapter(imageAdapter);
			holder.txtDelte.setVisibility(View.GONE);
		}
	}

	@Override public int getItemCount()
	{
		return jobInfoList.size();
	}

	class MyViewHolder extends BaseViewHolder
	{
		@BindView(R.id.work_info_item_showReservoirPositionTv) TextView workKLbs;  //库位
		@BindView(R.id.work_info_item_showStorehouseTv) TextView txtCk;  //仓库
		@BindView(R.id.work_info_item_showUnitWeightTv) TextView txtWeight;  //单件重量
		@BindView(R.id.work_info_item_showNumberForPieceTv) EditText txtPiece;  //数量件
		@BindView(R.id.work_info_item_showWeightForTonTv) EditText txtTon;  //数量吨
		@BindView(R.id.work_info_item_showVolumeForSquareTv) EditText txtSquare; //体积
		@BindView(R.id.work_info_item_showInventoryStatusTv) TextView txtStatus; //库存状态
		@BindView(R.id.work_info_item_showInventoryTypeTv) TextView txtType;//库存类型
		@BindView(R.id.work_info_item_showStandardTv) TextView txtGuiGe;//规格
		@BindView(R.id.work_info_item_showBatchNumberTv) EditText txtPcNum;//批次号
		@BindView(R.id.work_info_item_showJobRecordTv) TextView txtWorkRecord;//作业记录
		@BindView(R.id.work_info_item_annexManagementTv) TextView txtMangaer; //附件管理字样(此处隐藏)
		@BindView(R.id.layout_beizhu) RelativeLayout layoutBeizu; //备注layout(隐藏)
		@BindView(R.id.work_info_item_sureWorkBtn) TextView txtSureWork;//确认作业(隐藏)
		@BindView(R.id.work_info_item_gridView) MyGridView myGridView;
		@BindView(R.id.work_info_item_workDeleteTv) TextView txtDelte;

		public MyViewHolder(View itemView)
		{
			super(itemView);
			workKLbs = (TextView) itemView.findViewById(R.id.work_info_item_showReservoirPositionTv);
			txtCk = (TextView) itemView.findViewById(R.id.work_info_item_showStorehouseTv);
			txtWeight = (TextView) itemView.findViewById(R.id.work_info_item_showUnitWeightTv);
			txtPiece = (EditText) itemView.findViewById(R.id.work_info_item_showNumberForPieceTv);
			txtStatus = (TextView) itemView.findViewById(R.id.work_info_item_showInventoryStatusTv);
			txtTon = (EditText) itemView.findViewById(R.id.work_info_item_showWeightForTonTv);
			txtSquare = (EditText) itemView.findViewById(R.id.work_info_item_showVolumeForSquareTv);
			txtType = (TextView) itemView.findViewById(R.id.work_info_item_showInventoryTypeTv);
			txtGuiGe = (TextView) itemView.findViewById(R.id.work_info_item_showStandardTv);
			txtPcNum = (EditText) itemView.findViewById(R.id.work_info_item_showBatchNumberTv);
			txtWorkRecord = (TextView) itemView.findViewById(R.id.work_info_item_showJobRecordTv);
			txtMangaer = (TextView) itemView.findViewById(R.id.work_info_item_annexManagementTv);
			layoutBeizu = (RelativeLayout) itemView.findViewById(R.id.layout_beizhu);
			txtSureWork = (TextView) itemView.findViewById(R.id.work_info_item_sureWorkBtn);
			myGridView = (MyGridView) itemView.findViewById(R.id.work_info_item_gridView);
			txtDelte = (TextView) itemView.findViewById(R.id.work_info_item_workDeleteTv);
		}
	}

}
